package cn._tedu.eguser1.eguser1.base.response;

import lombok.Data;

/**
 * @author tune_the last
 * @date 2025/11/13 - 10:49
 * Lombok提供的注解
 * 1.@Sertter
 * 2.@Getter
 * 3.@ToString
 * 4.@AllArgsConstructor
 * 5.@NoArgsConstructor
 * 6.@Data
 */
@Data
public class Result<T> {
    //状态码、提示消息、具体数据
    private Integer state;
    private String message;
    private T data;

    private static <T> Result<T> build(T data, StatusCode statusCode){
        Result<T> result= new Result<>();
        result.setData(data);
        result.setState(statusCode.getState());
        result.setMessage(statusCode.getMessage());
        return result;
    }

    public static <T> Result<T> ok(){
        return build(null, StatusCode.OPERATiON_SUCCESS);
    }

    public static <T> Result<T> ok(T data){
        return build(data, StatusCode.OPERATiON_SUCCESS);
    }

    public static <T> Result<T> fail(){
        return build(null, StatusCode.OPERATiON_FAIL);
    }
    public static <T> Result<T> fail(T data){
        return build(data, StatusCode.OPERATiON_FAIL);
    }
    public static <T> Result<T> fail(StatusCode statusCode){
        return build(null, statusCode);
    }
    public static <T> Result<T> fail(StatusCode statusCode, T data){
        return build(data, statusCode);
    }
}
